package br.com.lh.urabuilder.util
{
	import flash.display.CapsStyle;
	import flash.display.JointStyle;
	import flash.display.LineScaleMode;
	import flash.display.Shape;
	import flash.geom.Point;
	
	import mx.binding.utils.BindingUtils;
	import mx.collections.ArrayCollection;
	import mx.core.UIComponent;
	
	[Bindable]
	public class PointHolder
	{
		public var parentX:Number;
		public var parentY:Number;
		public var topPoint:Point;
		public var bottomPoint:Point;
		public var leftPoint:Point;
		public var rightPoint:Point;
		private var parent:UIComponent;
		private var centerX:Number;
		private var centerY:Number;
		private var height:Number;
		private var width:Number;
		
		public function PointHolder(width:Number,height:Number,parent:UIComponent){
			this.parent = parent;
			this.centerX= width/2;
			this.centerY= height/2;
			this.height = height;
			this.width = width;
			this.parentX = parent.x;
			this.parentY = parent.y;
			topPoint = buildInternalPoint(centerX ,centerY - height/2 -10);
			bottomPoint =buildInternalPoint(centerX ,centerY + height/2);
			leftPoint = buildInternalPoint(centerX -width/2 - 10,centerY);
			rightPoint =buildInternalPoint(centerX + width/2 + 15,centerY);
			BindingUtils.bindSetter(rebuildInternalX,parent,"x");
			BindingUtils.bindSetter(rebuildInternalY,parent,"y");
		}
		
		private function rebuildInternalX(parentX:Number):void{
			this.parentX = parentX;
			rebuildInternal();
		}
		
		private function rebuildInternalY(parentY:Number):void{
			this.parentY = parentY;
			rebuildInternal();
		}
		
		private function rebuildInternal():void{
			topPoint = buildInternalPoint(centerX ,centerY - height/2 -10);
			bottomPoint =buildInternalPoint(centerX ,centerY + height/2);
			leftPoint = buildInternalPoint(centerX -width/2 -15,centerY);
			rightPoint =buildInternalPoint(centerX + width/2 + 5,centerY);		
		}
		
		private function buildInternalPoint(x:Number,y:Number):Point{
			return new Point(x + parentX,y + parentY);
		}
		
		
		
		
		
		
		
		
		

	}
}